// src/main/java/com/chixing/service/impl/MessageServiceImpl.java
package com.chixing.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chixing.entity.Message;
import com.chixing.mapper.MessageMapper;
import com.chixing.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements IMessageService {

    @Autowired
    private MessageMapper messageMapper;
    @Override
    public void saveOfflineMessage(Integer userId, String content) {
        Message message = new Message();
        message.setUserId(userId);
        message.setContent(content);
        message.setStatus(0); // 未读状态
        message.setCreateTime(LocalDateTime.now());
        message.setUpdateTime(LocalDateTime.now());
        this.save(message);
    }
    @Override
    public List<String> getUnreadMessages(Long userId){
        return messageMapper.getUnreadMessages(userId);
    }

    @Override
    public void markMessagesAsRead(Long userId){
        messageMapper.markMessagesAsRead(userId);
    }

}
